package com.ukao.cashregister.dialog;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;

import com.ukao.cashregister.R;
import com.ukao.cashregister.base.BaseDialogFragment;
import com.ukao.cashregister.eventbus.PayEvent;
import com.ukao.cashregister.listener.OnDialogSureClickListener;
import com.ukao.cashregister.utils.CheckUtils;
import com.ukao.cashregister.utils.SystemUIUtils;
import com.ukao.cashregister.utils.SystemUtils;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.Unbinder;

/**
 * 是否删除
 * Created by ukaodev on 2017/6/2.
 */

public class InquiryDialogFragment extends BaseDialogFragment {


    @BindView(R.id.loss_information)
    TextView lossInformation;
    @BindView(R.id.cancel)
    Button cancel;
    @BindView(R.id.submit)
    Button submit;
    private Unbinder unbinder;
    private OnDialogSureClickListener mOnDialogSureClickListener;
    private String hite;
    private int typeEnter;
    private boolean isRefundEnter;

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (getArguments() != null) {
            hite=getArguments().getString(ARG_PARAM1);
            isRefundEnter=getArguments().getBoolean(ARG_PARAM2,false);
        }

    }

    /**
     *
     * @param param1
     * @param isRefundEnter  是否是退款
     * @return
     */
    public static InquiryDialogFragment newInstance(String param1,boolean  isRefundEnter  ) {
        InquiryDialogFragment fragment = new InquiryDialogFragment();
        Bundle args = new Bundle();
        args.putString(ARG_PARAM1, param1);
        args.putBoolean(ARG_PARAM2, isRefundEnter);
        fragment.setArguments(args);
        return fragment;
    }

    public static InquiryDialogFragment newInstance(String param1    ) {
        InquiryDialogFragment fragment = new InquiryDialogFragment();
        Bundle args = new Bundle();
        args.putString(ARG_PARAM1, param1);
        fragment.setArguments(args);
        return fragment;
    }
    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.dialog_inquiry_layout, container, false);
        unbinder = ButterKnife.bind(this, view);

        return view;
    }


    public void setOnSureClickListener(OnDialogSureClickListener mOnDialogSureClickListener) {
        this.mOnDialogSureClickListener= mOnDialogSureClickListener;
    }


    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        if (getDialog()!=null)
        SystemUIUtils.setStickFullScreen(getDialog().getWindow());
        if(!CheckUtils.isEmpty(hite)){
            lossInformation.setText(hite);
        }
        if (isRefundEnter){
            submit.setTextColor(getColors(R.color.black));
            cancel.setText("关闭");


        }


    }


    @Override
    public void onDestroyView() {
        super.onDestroyView();
        unbinder.unbind();
    }


    @OnClick({R.id.cancel, R.id.submit})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.cancel:
                dismiss();
                break;
            case R.id.submit:

                if (mOnDialogSureClickListener!=null){
                    mOnDialogSureClickListener.onSureItemClick("");
                }
                if (!isRefundEnter){
                    PayEvent.postNoData(PayEvent.Message.returnWash);
                }

                dismiss();

                break;

        }
    }


}
